/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.schedule.core.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.component.schedule.facade.command.ScheduleJobServiceFacade;
import info.peigen.hotpot.component.schedule.facade.command.order.ScheduleJobChangeAllOrder;
import info.peigen.hotpot.component.schedule.facade.command.order.ScheduleJobCreateOrder;
import info.peigen.hotpot.component.schedule.facade.command.order.ScheduleJobDeleteOrder;
import info.peigen.hotpot.component.schedule.facade.command.order.ScheduleJobEditOrder;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleJobChangeAllResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleJobCreateResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleJobDeleteResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleJobEditResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(ScheduleJobService)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/6
 */
@Component
public class ScheduleJobService extends AbstractScheduleService implements ScheduleJobServiceFacade {
    @Override
    public ScheduleJobCreateResult create(ScheduleJobCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ScheduleJobCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleJobCreateProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleJobCreateResultProcessor, scheduleJobStoreProcessor);
            }
        });
        return (ScheduleJobCreateResult) serviceContext.getResult();
    }

    @Override
    public ScheduleJobEditResult edit(ScheduleJobEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ScheduleJobEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleJobActiveProcessor, scheduleJobEditProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleJobEditResultProcessor, scheduleJobStoreProcessor);
            }
        });
        return (ScheduleJobEditResult) serviceContext.getResult();
    }

    @Override
    public ScheduleJobDeleteResult delete(ScheduleJobDeleteOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ScheduleJobDeleteResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors();
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleJobDeleteProcessor, scheduleJobDeleteResultProcessor);
            }
        });
        return (ScheduleJobDeleteResult) serviceContext.getResult();
    }

    @Override
    public ScheduleJobChangeAllResult changeAll(ScheduleJobChangeAllOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ScheduleJobChangeAllResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors();
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleJobChangeAllProcessor, scheduleJobChangeAllResultProcessor);
            }
        });
        return (ScheduleJobChangeAllResult) serviceContext.getResult();
    }
}
